package app.controllers.admin.stat;

import app.Const;
import app.models.brand.DailyStat;
import com.github.sog.controller.BasicController;
import com.github.sog.controller.datatables.core.DatatablesCriterias;
import com.github.sog.render.JxlsRender;
import com.google.common.collect.Maps;
import com.jfinal.plugin.activerecord.Page;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 品牌每日统计
 * </p>
 *
 * @author liuhui
 * @version 1.0 2014-06-05 10:40
 * @since JDK 1.6
 */
public class BrandController extends BasicController {

    public void index() {
        render("index.ftl");
    }

    public void list() {
        final DatatablesCriterias criterias = getCriterias();
        String start_date = getPara("start_date");
        String end_date = getPara("end_date");
        Page<DailyStat> pageRt = DailyStat.dao.datatable(criterias, start_date, end_date);
        renderDataTables(pageRt, criterias);
    }


    public void export() {
        String start_date = getPara("start_date");
        String end_date = getPara("end_date");
        List<DailyStat> stats = DailyStat.dao.findByBeginAndEndDate(start_date, end_date);
        Map<String, Object> _excel_datas = Maps.newHashMap();

        _excel_datas.put(Const.Report.RECORD_ATTR, stats);
        render(JxlsRender.me(Const.Report.BRAND_DAIYL_REPORT_PATH).filename("品牌统计访问表.xlsx").beans(_excel_datas));
    }

}
